home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / netlib / utime.c < prev   
C/C++ Source or Header  |  1994-03-29  |  3KB  |  127 lines

  1. RCS_ID_C="$Id: utime.c,v 3.1 1994/03/29 12:56:35 ppessi Exp $"
  2. /*
  3.  * utime.c --- set the modification date of the file
  4.  *
  5.  * Author: jraja <Jarno.Rajahalme@hut.fi>
  6.  *
  7.  * Copyright © 1994 AmiTCP/IP Group, <amitcp-group@hut.fi>
  8.  *                  Helsinki University of Technology, Finland.
  9.  *                  All rights reserved.
  10.  *
  11.  * Created      : Thu Mar 24 22:30:12 1994 jraja
  12.  * Last modified: Mon Mar 28 01:53:14 1994 ppessi
  13.  *
  14.  * $Log: utime.c,v $
  15.  * Revision 3.1  1994/03/29  12:56:35  ppessi
  16.  * Made to use netlib.h
  17.  *
  18.  * Revision 1.1  1994/03/27  11:53:06  jraja
  19.  * Initial revision
  20.  *
  21.  *
  22.  */
  23.  
  24. #include <sys/param.h>
  25. #include <sys/time.h>
  26. #include <dos/dos.h>
  27. #include <proto/dos.h>
  28. #include <utime.h>
  29. #include <errno.h>
  30.  
  31. #include <syslog.h>
  32.  
  33. #include "netlib.h"
  34.  
  35. /****** net.lib/utime *********************************************
  36.  
  37.     NAME
  38.     utime - set file access and modification times
  39.  
  40.     SYNOPSIS
  41.     #include <utime.h>
  42.  
  43.     int error = utime(const char *name, const struct utimbuf *times)
  44.  
  45.     FUNCTION
  46.     The access and modification times for the file 'name' are modified
  47.     according to the 'times'. If 'times' is NULL, the times are set to
  48.     systems current time.
  49.  
  50.     PORTABILITY
  51.     UNIX
  52.  
  53.     INPUTS
  54.     'name'  - the name of the file to be affected.
  55.  
  56.     'times' - pointer to a structure containing the time values,
  57.           defined in <utime.h> as:
  58.  
  59.               struct utimbuf {
  60.               time_t actime;    \* Access time *\
  61.               time_t modtime;    \* Modification time *\
  62.               };
  63.  
  64.           Both times are in units of seconds since Jan. 1, 1970,
  65.           Greenwich Mean Time.
  66.  
  67.           If the 'times' is given as the NULL pointer, the current
  68.           time is used.
  69.  
  70.     RESULT
  71.     Returns 0 when successful and -1 with specific error code in errno in
  72.     case of an error.
  73.  
  74.     NOTES
  75.     Since AmigaDOS files have only one time stamp, both access and
  76.     modification times cannot be supported. Since the AmigaDOS file date
  77.     is the modification time, only the 'modtime' field of the 'times' is
  78.     used.
  79.  
  80.     The conversion from 1.1.1970 based GMT to 1.1.1978 based local time is
  81.     done with external long __local_to_GMT, which is defined and
  82.     initialized by the timerinit.c module included in the net.lib.
  83.  
  84.     SEE ALSO
  85.     dos.library/DateStamp(), dos.library/SetFileDate(), net.lib/timerinit
  86.  
  87. *****************************************************************************
  88. *
  89. */
  90.  
  91. extern long __local_to_GMT; /* defined and initialized in timerinit.c */
  92.  
  93. int
  94. utime(const char *name, const struct utimbuf *times)
  95. {
  96.   struct DateStamp stamp;
  97.   unsigned long days, secs;
  98.   time_t time;
  99.  
  100.   if (times == NULL)
  101.     DateStamp(&stamp);
  102.   else {
  103.     /*
  104.      * AmigaDOS file date is the modification time
  105.      */
  106.     time = times->modtime;
  107.  
  108.     /*
  109.      * Convert time (secs since 1.1.1970 GMT) to
  110.      * AmigaDOS DateStamp (based on 1.1.1978 local time).
  111.      */
  112.     time -= __local_to_GMT; /* GMT to local */
  113.     days = (unsigned long)time / (unsigned long)(24*60*60);
  114.     secs = (unsigned long)time % (unsigned long)(24*60*60);
  115.     stamp.ds_Days = (LONG)days;
  116.     stamp.ds_Minute = (LONG)(secs / 60);
  117.     stamp.ds_Tick = (LONG)((secs % 60) * TICKS_PER_SECOND);
  118.   }
  119.  
  120.   if (!SetFileDate(name, &stamp)) {
  121.     set_errno(IoErr());
  122.     return -1;
  123.   }
  124.  
  125.   return 0;
  126. }
  127.